package ar.edu.unq.mongodbexample.homes;

import java.util.List;

import org.bson.types.ObjectId;

import ar.edu.unq.mongodbexample.model.ApprovalStrategy;
import ar.edu.unq.mongodbexample.persistence.MongoDBManager;

import com.google.code.morphia.dao.BasicDAO;

/**
 * @author Cappa Hernan
 * 
 *         TODO: description
 */
public class ApprovalStrategyHome extends BasicDAO<ApprovalStrategy, ObjectId> implements IHome<ApprovalStrategy> {

    public ApprovalStrategyHome() {
        super(ApprovalStrategy.class, MongoDBManager.getInstance().getDataStore());
        MongoDBManager.getInstance().getMorphia().map(ApprovalStrategy.class);

    }

    public int saveAll(final List<ApprovalStrategy> approval) {
        int notSaved = 0;
        try {
            for (ApprovalStrategy st : approval) {
                this.save(st);
            }
        } catch (Exception e) {
            // TODO: handle exception
            notSaved++;
        }
        return notSaved;
    }

    public List<ApprovalStrategy> getAll() {
        return this.ds.find(ApprovalStrategy.class).asList();
    }

    public ApprovalStrategy findById(final Object id) {
        return this.ds.get(ApprovalStrategy.class, id);
    }

}
